package com.proj.controller;

import com.proj.bean.Category;
import com.proj.service.ICategoryService;
import com.proj.util.LayData;
import com.proj.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
//标注是controller，并将生命周期纳入IOC容器生命周期进行管理
@RequestMapping("category")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;

    @RequestMapping("list")
    @ResponseBody
    public LayData getList(Page page, String text){
        List<Category> list = categoryService.getList(page, text);
        int count=categoryService.getCount(text);
        return new LayData(count, list);
    }

    @RequestMapping("del")
    @ResponseBody
    public int del(int id){
        return categoryService.del(id);
    }

    @RequestMapping("getchildren")
    @ResponseBody
    public List<Category> getChildren(int id){
        return categoryService.getChildren(id);
    }

    @RequestMapping("add")
    @ResponseBody
    public int add(Category category){
        return categoryService.add(category);
    }


    @RequestMapping("edit")
    @ResponseBody
    public int edit(Category category){
        return categoryService.edit(category);
    }


}
